package com.hzqy.service.epg;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hzqy.persistence.dao.epg.HappyDao;
import com.hzqy.web.vo.CmContentVo;

@Service
public class HappyServiceBean {
	
	@Resource
	private HappyDao happyDao;

	public Map<String, Object> selectHappyList(CmContentVo ccv, int page, int rows) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_cc_name", ccv.getF_cc_name());
		map.put("f_cc_code", ccv.getF_cc_code());
		map.put("f_cc_director", ccv.getF_cc_director());
		map.put("f_cc_status", ccv.getF_cc_status());
		map.put("f_cc_seriescount", ccv.getF_cc_seriescount());
		map.put("f_avu_activityid", "44");
		int rowCount = happyDao.selectHappyCount(map);
		map.put("total", rowCount);
		if(rowCount > 0 && page > 0 && rows > 0) {
			map.put("firstResult", (page-1)*rows);
			map.put("maxResults", rows);
			List<CmContentVo> results =happyDao.selectHappyList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<CmContentVo>());
		}
		return map;
	}

	public Map<String, Object> selectHappyListExcel(CmContentVo ccv) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_cc_name", ccv.getF_cc_name());
		map.put("f_cc_code", ccv.getF_cc_code());
		map.put("f_cc_status", ccv.getF_cc_status());
		map.put("f_cc_director", ccv.getF_cc_director());
		map.put("f_cc_seriescount", ccv.getF_cc_seriescount());
		map.put("f_avu_activityid", "44");
		int rowCount = happyDao.selectHappyCount(map);
		map.put("total", rowCount);
		if(rowCount > 0 ) {
			List<CmContentVo> results =happyDao.selectHappyListExcel(map);
			for (int i = 0; i < results.size(); i++) {
				if(results.get(i).getRoleId()==null||"".equals(results.get(i).getRoleId()))
					results.get(i).setRoleId("0");
				results.get(i).setSctt_startDate(sdf.format(results.get(i).getF_cc_cdate()));
				results.get(i).setSctt_endDate(sdf.format(results.get(i).getF_cc_udate()));
			}
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<CmContentVo>());
		}
		return map;
	}
	public int insertVoteUser(Map<String, Object> map) {
		return happyDao.insertVoteUser(map);
	}
	public int updateContenStatus(int fccid) {
		Map<String,Object> map = new HashMap<String, Object>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("f_cc_id", fccid);
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(calendar.DAY_OF_MONTH, 30);
		Date date=calendar.getTime();
		map.put("f_cc_onlinedate", sdf.format(date));
		return happyDao.updateContenStatus(map);
	}
	
	public int deleteContenStatus(int fccid) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_cc_id", fccid);
		return happyDao.deleteContenStatus(map);
	}
	
	public int ContenStatusNo(int fccid,String f_cc_remark) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_cc_id", fccid);
		map.put("f_cc_remark", f_cc_remark);
		return happyDao.ContenStatusNo(map);
	}
}
